package com.syz.fs.file;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;

import java.util.logging.Logger;

/**
 * client 处理
 * 
 * @author SYZ
 * @date 2017年11月23日 上午9:05:22
 * @version 1.0.0
 * @see com.syz.fs.file.FileClientHandler
 */
public class FileClientHandler extends SimpleChannelInboundHandler<String> {

	private static final Logger logger = Logger
			.getLogger(FileClientHandler.class.getName());

	private byte[] req;

	/**
	 * Creates a client-side handler.
	 */
	public FileClientHandler() {
		req = ("D:\\project\\get-Next\\Net-Server-MQ\\vertx\\pom.xml"+System.getProperty("line.separator"))
				.getBytes();
	}

	@Override
	public void channelActive(ChannelHandlerContext ctx) {
/*		ByteBuf message = Unpooled.buffer(req.length);
			message.writeBytes(req);
			ctx.writeAndFlush(message);*/
	}


	@Override
	public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
		// 释放资源
		logger.warning("Unexpected exception from downstream : "
				+ cause.getMessage());
		ctx.close();
	}


	@Override
	protected void channelRead0(ChannelHandlerContext arg0, String body)
			throws Exception {
		System.out.println("[rcv]: " + body );
	}
}
